<template>
    <view>
        <!-- pages/orderDetail/orderDetail.wxml -->

        <view class="container">
            <view class="top-container">
                <view class="top">
                    <view class="info">
                        <view>
                            <image class="roomImg" :src="magic.split(OrderInfodata.roomImg)[0]"></image>
                        </view>
                        <view class="name">
                            {{ OrderInfodata.roomName }}（{{
                                OrderInfodata.roomType == 1
                                    ? '小包'
                                    : OrderInfodata.roomType == 2
                                    ? '中包'
                                    : OrderInfodata.roomType == 3
                                    ? '大包'
                                    : OrderInfodata.roomType == 4
                                    ? '豪包'
                                    : '商务包'
                            }}）
                        </view>
                        <view class="share">
                            <button class="share bg-primary" open-type="share"><text>分享</text></button>
                        </view>
                    </view>
                </view>
                <!-- 时间段 -->
                <view class="timeBox">
                    <view class="time">
                        <view class="hour">{{ magic.splittime(OrderInfodata.startTime)[0] }}:{{ magic.splittime(OrderInfodata.startTime)[1] }}</view>
                        <view class="date">{{ magic.splitkongge(OrderInfodata.startTime)[0] }}</view>
                    </view>
                    <view class="total border-primary">{{ OrderInfodata.orderHour }}小时</view>
                    <view class="time">
                        <view class="hour">{{ magic.splittime(OrderInfodata.endTime)[0] }}:{{ magic.splittime(OrderInfodata.endTime)[1] }}</view>
                        <view class="date">{{ magic.splitkongge(OrderInfodata.endTime)[0] }}</view>
                    </view>
                </view>
                <!-- 订单详情 -->
                <view class="orderInfo">
                    <view class="item">
                        <view class="title">订单编号：</view>
                        <view class="logo">
                            {{ OrderInfodata.orderNo }}
                        </view>
                    </view>
                    <view class="item">
                        <view class="title">门店名称：</view>
                        <view class="logo">
                            {{ OrderInfodata.storeName }}
                            <text class="color-primary link" @tap="goTencentMap">查看地图</text>
                        </view>
                    </view>
                    <view class="item">
                        <view class="title">支付方式：</view>
                        <text>{{ OrderInfodata.payType === 1 ? '微信' : OrderInfodata.payType === 2 ? '余额' : OrderInfodata.payType === 3 ? '团购' : '套餐' }}</text>
                    </view>
                    <block v-if="OrderInfodata.deposit">
                        <view class="item">
                            <view class="title">支付押金：</view>
                            <text>¥ {{ OrderInfodata.deposit }} 元</text>
                        </view>
                    </block>
                    <view class="item">
                        <label class="title">使用卡券：</label>
                        <block v-if="OrderInfodata.couponName.length > 0">
                            <text>{{ OrderInfodata.couponName }}</text>
                        </block>
                        <block v-else>
                            <text>暂无</text>
                        </block>
                    </view>
                    <view class="item">
                        <label class="title">下单时间：</label>
                        <text>{{ OrderInfodata.createTime }}</text>
                    </view>
                    <!-- wifi -->
                    <view class="item" v-if="OrderInfodata.status == 0 || OrderInfodata.status == 1">
                        <label class="title">WIFI信息：</label>
                        <view class="color-primary wifi">
                            {{ OrderInfodata.wifiInfo }}
                        </view>
                    </view>
                    <view class="item" v-if="OrderInfodata.status == 0 || OrderInfodata.status == 1">
                        <label class="title">WIFI密码：</label>
                        <view class="color-primary wifi">
                            {{ OrderInfodata.wifiPwd }}
                        </view>
                    </view>
                </view>
            </view>
            <view class="order-container">
                <view class="doors" v-if="OrderInfodata.status === 0 || OrderInfodata.status === 1">
                    <view class="door m-b-20 color-primary" @tap="damenbindchange">
                        <view class="action">
                            <view class="iconfont icon-damen"></view>
                            <view class="text">门店大门</view>
                        </view>
                    </view>
                    <view class="door m-b-20 color-primary" @tap="bindOpenRoomLock">
                        <view class="action">
                            <view class="iconfont icon-damen"></view>
                            <view class="text">蓝牙开锁</view>
                        </view>
                    </view>
                    <view class="door m-b-20 color-primary" @tap="roombindchange">
                        <view class="action">
                            <view class="iconfont icon-dian"></view>
                            <view class="text">通电开门</view>
                        </view>
                    </view>
                    <button
                        hover-class="button-click"
                        :class="'door color-primary share ' + (OrderInfodata.renewBtn ? '' : 'disabled')"
                        :open-type="OrderInfodata.renewBtn ? 'share' : ''"
                    >
                        <view class="action">
                            <view class="iconfont icon-fenxiang"></view>
                            <view class="text">分享订单</view>
                        </view>
                    </button>
                    <view :class="'door color-primary ' + (OrderInfodata.renewBtn ? 'color-primary' : 'disabled')">
                        <view class="action" @tap="call">
                            <view class="iconfont icon-kefu"></view>
                            <view class="text">联系客服</view>
                        </view>
                    </view>
                    <view :class="'door color-primary ' + (OrderInfodata.renewBtn ? 'color-primary' : 'disabled')" @tap="renewClick">
                        <view class="action">
                            <view class="iconfont icon-shalou"></view>
                            <view class="text">续费</view>
                        </view>
                    </view>
                    <view class="tip">Tips：分享房间给好友，好友可直接操作开门开电</view>
                    <view class="bar_btns" v-if="OrderInfodata.status === 0">
                        <view class="btnSmall left" @tap="cancelOrder" :data-info="OrderInfodata.status">取消订单</view>
                        <view class="btnSmall right" @tap="goChangeDoor">更换房间</view>
                    </view>
                    <view class="bar_btns" v-if="OrderInfodata.status === 1">
                        <view class="btnSmall left" @tap="stopOrder" :data-id="OrderInfodata.orderId">提前离店</view>
                    </view>
                </view>
                <view class="doors" v-else>
                    <view :class="'door ' + (OrderInfodata.renewBtn ? 'color-primary' : 'disabled')">
                        <view class="action" @tap="call">
                            <view class="iconfont icon-kefu"></view>
                            <view class="text">联系客服</view>
                        </view>
                    </view>
                    <view :class="'door ' + (OrderInfodata.renewBtn ? 'color-primary' : 'disabled')" @tap="renewClick">
                        <view class="action">
                            <view class="iconfont icon-shalou"></view>
                            <view class="text">续费</view>
                        </view>
                    </view>
                </view>
            </view>
            <!-- 温馨提示 -->
            <view class="notes">
                <view class="title border-primary">温馨提示</view>
                <view class="line">1. 下单5分钟内可以取消订单或更换房间，超时将无法取消！</view>
                <view class="line">2. 订单无法暂停，迟到消费，按原预订时间开始计费！</view>
                <view class="line">3. 订单可以提前开始消费，提前开始提前结束。</view>
                <view class="line">4. 特殊情况，或需要帮助，请联系客服处理！</view>
                <view class="line">5. 离场时请带好随身物品，以防丢失！</view>
                <view class="line">6.支付的押金,在订单结束5分钟后,自动原路退回！</view>
            </view>
        </view>
        <!-- 续单弹窗 -->
        <van-dialog use-slot title="订单续费" :show="renewShow" show-cancel-button :before-close="beforeCloseFunction">
            <view class="dialog">
                <view class="item" style="align-items: center">
                    <label>请选择增加的时间：</label>
                    <van-stepper :value="addTime" step="1" min="0" max="8" disable-input @change="onChange" />
                    时
                </view>
                <view class="item">
                    <label>订单原结束时间：</label>
                    <text>{{ OrderInfodata.endTime }}</text>
                </view>
                <view class="item">
                    <label>增加后结束时间：</label>
                    <text>{{ newTime }}</text>
                </view>
                <view class="item">
                    <label>小时单价：</label>
                    <text class="color-attention">{{ OrderInfodata.roomPrice }}元</text>
                    /小时
                </view>
                <block v-if="OrderInfodata.roomPrice != OrderInfodata.workPrice">
                    <view class="item">
                        <label>闲时单价：</label>
                        <text class="color-attention">{{ OrderInfodata.workPrice }}元</text>
                        /小时
                    </view>
                </block>
                <view class="item">
                    <label>支付总价：</label>
                    <text class="color-attention">{{ totalPay }}</text>
                    元
                </view>
                <view class="item pay-item">
                    <label>支付方式：</label>
                    <radio-group class="pays" @change="radioChange">
                        <label class="pay" v-for="(item, index) in payTypes" :key="index">
                            <view class="left">
                                <view v-if="item.value === 1" class="iconfont icon-weixinzhifu color-primary"></view>
                                <view v-if="item.value === 2" class="iconfont icon-pay color-primary"></view>
                                {{ item.name }}
                            </view>

                            <view class="wallet-info" v-if="item.value === 2">
                                <view class="info">账户余额: {{ balance }}元</view>
                                <view class="info">赠送余额: {{ giftBalance }}元</view>
                            </view>

                            <radio :value="item.value" :checked="item.checked" />
                        </label>
                    </radio-group>
                </view>
            </view>
        </van-dialog>
        <!-- 取消订单弹窗 -->
        <van-dialog use-slot title="取消订单" :show="cancelOrderShow" show-cancel-button cancel-button-text="暂不取消" confirm-button-text="确认取消" @confirm="cancelConfirm">
            <view class="dialog">
                <view class="item">
                    <label>当前位置：</label>
                    <text>
                        {{ OrderInfodata.storeName }} {{ OrderInfodata.roomName }}（{{
                            OrderInfodata.roomType == 1
                                ? '小包'
                                : OrderInfodata.roomType == 2
                                ? '中包'
                                : OrderInfodata.roomType == 3
                                ? '大包'
                                : OrderInfodata.roomType == 4
                                ? '豪包'
                                : '商务包'
                        }}）
                    </text>
                </view>
                <view class="item">
                    <label>预约时间：</label>
                    <text>{{ OrderInfodata.createTime }}</text>
                </view>
                <view class="item">
                    <label>是否确认取消订单？</label>
                </view>
                <view class="item">
                    <p class="color-attention note">取消订单后，费用将会退还到您原支付方式账户中！</p>
                </view>
            </view>
        </van-dialog>
        <!-- 取消订单成功弹窗 -->
        <van-dialog use-slot title="订单取消成功" :show="cancelOrderSuccess" confirm-button-text="好的" @confirm="SucessConfirm">
            <view class="dialog">
                <view class="item">
                    <label>已为您成功取消下列订单</label>
                </view>
                <view class="item">
                    <label>当前位置：</label>
                    <block v-if="OrderInfodata.roomType == 0">
                        <text>{{ OrderInfodata.storeName }} {{ OrderInfodata.roomName }} （特价包）</text>
                    </block>
                    <block v-else-if="OrderInfodata.roomType == 1">
                        <text>{{ OrderInfodata.storeName }} {{ OrderInfodata.roomName }} （小包）</text>
                    </block>
                    <block v-else-if="OrderInfodata.roomType == 2">
                        <text>{{ OrderInfodata.storeName }} {{ OrderInfodata.roomName }} （中包）</text>
                    </block>
                    <block v-else-if="OrderInfodata.roomType == 3">
                        <text>{{ OrderInfodata.storeName }} {{ OrderInfodata.roomName }} （大包）</text>
                    </block>
                    <block v-else-if="OrderInfodata.roomType == 4">
                        <text>{{ OrderInfodata.storeName }} {{ OrderInfodata.roomName }} （豪包）</text>
                    </block>
                    <block v-else>
                        <text>{{ OrderInfodata.storeName }} {{ OrderInfodata.roomName }} （商务包）</text>
                    </block>
                </view>
                <view class="item">
                    <label>预约时间：</label>
                    <text>{{ OrderInfodata.createTime }}</text>
                </view>
                <view class="item">
                    <view class="color-attention note">订单取消成功，费用已返还到原支付账户！</view>
                </view>
            </view>
        </van-dialog>
    </view>
</template>
<script module="magic" lang="wxs" src="@/utils/magic.wxs"></script>
<script>
// pages/orderDetail/orderDetail.js
const app = getApp();
var http = require('../../utils/http');
var lock = require('../../utils/lock.js');
var Moment = require('../../lib/moment.js');

// const { TABLE } = require('XrFrame/core/Component');

export default {
    data() {
        return {
            renewShow: false,

            //续费弹窗
            cancelOrderShow: false,

            //订单取消弹窗
            cancelOrderSucShow: false,

            //取消成功弹窗
            OrderNo: '',

            //订单id
            orderKey: '',

            //订单key  用于分享好友 直接打开使用
            isLogin: app.globalData.isLogin,

            OrderInfodata: {
                roomName: '',
                roomType: 0,
                orderHour: '',
                orderNo: '',
                payType: 0,
                deposit: '',
                couponName: [],
                createTime: '',
                status: 0,
                wifiInfo: '',
                wifiPwd: '',
                renewBtn: false,
                orderId: '',
                endTime: '',
                roomPrice: '',
                workPrice: '',
                storeName: ''
            },

            RoomImageList: [],

            //房间图片数组
            damenSwitchBool: false,

            roomSwitchBool: false,
            userinfo: {},

            //用户信息
            addTime: 0,

            //续费时长
            newTime: '',

            //增加后的时间
            totalPay: 0,

            //增加后支付价格
            beforeCloseFunction: null,

            payTypes: [
                {
                    name: '微信支付',
                    value: 1,
                    checked: true
                },
                {
                    name: '钱包余额',
                    value: 2
                }
            ],

            payType: 1,
            weixinOrderNo: '',

            //支付订单号
            renewOrderNo: '',

            //续费订单号
            giftBalance: '',

            balance: '',
            cancelOrderSuccess: false
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        var that = this;
        that.setData({
            isLogin: app.globalData.isLogin
        });
        var OrderNo = '';
        var orderKey = '';
        if (options.OrderNo) {
            OrderNo = options.OrderNo;
        }
        if (options.orderKey) {
            orderKey = options.orderKey;
        }
        if (!options.toPage) {
            var query = uni.getEnterOptionsSync().query;
            if (query) {
                if (query.OrderNo) {
                    OrderNo = query.OrderNo;
                }
                if (query.orderKey) {
                    orderKey = query.orderKey;
                }
            }
        }
        console.log(OrderNo);
        console.log(orderKey);
        that.setData({
            beforeCloseFunction: this.beforeClose(),
            OrderNo: OrderNo,
            orderKey: orderKey
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getrorderInfodata();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        let that = this;
        return {
            title: '打开订单，一键开门!',
            path: '/pages/orderDetail/orderDetail?toPage=true&orderKey=' + that.orderKey,
            success: function (res) {
                if (res.confirm) {
                    // 转发成功
                    uni.showToast({
                        title: '分享成功',
                        icon: 'success',
                        duration: 2000
                    });
                }
            },
            fail: function (res) {
                // 分享失败
            }
        };
    },
    methods: {
        share: function () {},

        // 确认到店
        startOrder: function () {
            let isBefore = Moment().isBefore(this.OrderInfodata.startTime);
            var that = this;
            if (isBefore) {
                uni.showModal({
                    title: '提示',
                    content: '订单将从当前时间开始计费。您确定要提前开始吗？',
                    cancelText: '继续等待',
                    confirmText: '现在开始',
                    complete: (res) => {
                        if (res.cancel) {
                        }
                        if (res.confirm) {
                            that.beginOrder();
                        }
                    }
                });
            } else {
                that.beginOrder();
            }
        },

        // 结束订单
        endOrder: function () {
            var that = this;
            uni.showModal({
                title: '提示',
                content: '由于订单已开始计费，提前结束将无法退款。因设备故障等原因导致无法正常消费的，请联系客服人工处理。请问您是否需要联系客服？',
                cancelText: '取消',
                confirmText: '联系客服',
                complete: (res) => {
                    if (res.cancel) {
                    }
                    if (res.confirm) {
                        that.call();
                    }
                }
            });
        },

        // 开始订单
        beginOrder: function () {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/order/startOrder/' + that.OrderInfodata.orderId,
                    '1',
                    'post',
                    {
                        orderId: that.OrderInfodata.orderId
                    },
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('返回111===');
                        console.info(info);
                        if (info.code == 0) {
                            uni.showToast({
                                title: '确认到店成功'
                            });
                            that.getrorderInfodata();
                        } else {
                            uni.showModal({
                                content: info.msg,
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        // 去更换房间
        goChangeDoor() {
            var orderInfo = {
                orderId: this.OrderInfodata.orderId,
                storeId: this.OrderInfodata.storeId,
                storeName: this.OrderInfodata.storeName,
                roomName: this.OrderInfodata.roomName,
                startTime: this.OrderInfodata.startTime,
                endTime: this.OrderInfodata.endTime,
                roomType: this.OrderInfodata.roomType,
                roomId: this.OrderInfodata.roomId,
                kefuPhone: this.OrderInfodata.kefuPhone
            };
            console.log(orderInfo);
            uni.navigateTo({
                url: '../changeDoor/changeDoor?orderInfo=' + JSON.stringify(orderInfo)
            });
        },

        // 续费弹窗
        renewClick() {
            var that = this;
            let OrderInfodata = that.OrderInfodata;
            if (OrderInfodata.status == 3 || OrderInfodata.status == 2) {
                uni.showToast({
                    title: '订单已结束！',
                    icon: 'error'
                });
            } else {
                this.setData({
                    renewShow: true,
                    payTypes: [
                        {
                            name: '微信支付',
                            value: 1,
                            checked: true
                        },
                        {
                            name: '钱包余额',
                            value: 2
                        }
                    ]
                });

                // var currentTimeStamp =  Date.now();
                // var specifiedTime =  new Date(OrderInfodata.endTime).getTime();
                // // 判断是否已经过去了5分钟（5 * 60 * 1000毫秒）
                // var isPastFiveMinutes = (currentTimeStamp - specifiedTime) > (5 * 60 * 1000);
                // // 判断订单结束时间是否在当前时间的5分钟前
                // if (isPastFiveMinutes) {
                //    wx.showModal({
                //       title: '温馨提示',
                //       content: '订单已结束超过5分钟，不允许续费！请重新下单！',
                //       showCancel: false,
                //       confirmText: "确定",
                //       success (res) {
                //       }
                //   })
                // } else {
                //   this.setData({
                //     renewShow: true,
                //     payTypes: [{name:'微信支付',value: 1,checked:true},{name:'钱包余额',value: 2}],
                //   })
                // }
            }
        },

        // 续费加时间
        onChange: function (event) {
            var that = this;
            var addTime = event.detail;
            // console.info('时间===');
            // console.info(addTime);
            var newTime = Moment(that.OrderInfodata.endTime).add(addTime, 'hours').format('YYYY/MM/DD HH:mm');
            //console.log(`newtime:${newTime}`)
            this.setData({
                addTime: addTime,
                // totalPay: addTime * that.data.orderInfo.price,
                newTime: newTime,
                totalPay: (addTime * this.getPrice(newTime)).toFixed(2)
            });
        },

        // 支付方式选择
        radioChange(e) {
            this.setData({
                payType: e.detail.value
            });
        },

        // 处理续费
        beforeClose() {
            var that = this;
            // 这里一定要用箭头函数，否则访问不到this
            return (type) => {
                //console.log(type)
                if (type === 'cancel') {
                    // 点击取消
                    // return true
                    that.renewCancel();
                } else {
                    // 点击确定
                    if (that.addTime < 0.5) {
                        uni.showToast({
                            title: '请选择增加时间!',
                            icon: 'error'
                        });
                        return;
                    }
                    that.SubmitOrderInfoData();
                }
            };
        },

        //预支付
        SubmitOrderInfoData() {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/order/preOrder',
                    '1',
                    'post',
                    {
                        roomId: that.OrderInfodata.roomId,
                        couponId: '',
                        startTime: that.OrderInfodata.endTime,
                        endTime: that.newTime,
                        orderId: that.OrderInfodata.orderId
                    },
                    app.globalData.userDatatoken.accessToken,
                    '提交中...',
                    function success(info) {
                        console.info('支付信息===');
                        console.info(info);
                        if (info.code == 0) {
                            that.renewOrderNo = info.data.orderNo;
                            //判断是不是微信支付 微信支付让回调去处理
                            if (that.payType == 1) {
                                that.lockWxOrder(info);
                            } else {
                                that.renewConfirm();
                            }
                        } else {
                            uni.showModal({
                                title: '温馨提示',
                                content: info.msg,
                                showCancel: false,
                                confirmText: '确定',
                                success(res) {}
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        // 锁定微信订单
        lockWxOrder: function (pay) {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/order/lockWxOrder',
                    '1',
                    'post',
                    {
                        roomId: that.OrderInfodata.roomId,
                        couponId: '',
                        startTime: that.OrderInfodata.endTime,
                        endTime: that.newTime,
                        orderId: that.OrderInfodata.orderId
                    },
                    app.globalData.userDatatoken.accessToken,
                    '提交中...',
                    function success(info) {
                        if (info.code == 0) {
                            console.log('锁定微信支付订单');
                            that.payMent(pay); //微信支付
                        } else {
                            uni.showModal({
                                title: '温馨提示',
                                content: info.msg,
                                showCancel: false,
                                confirmText: '确定',
                                success(res) {}
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        //支付
        payMent: function (pay) {
            var that = this;
            uni.requestPayment({
                timeStamp: pay.data.timeStamp,
                nonceStr: pay.data.nonceStr,
                package: pay.data.pkg,
                signType: pay.data.signType,
                paySign: pay.data.paySign,
                success: function (res) {
                    //console.log('*************支付成功');
                    // that.renewConfirm();
                    that.getrorderInfodata();
                    that.renewCancel();
                },
                fail: function (res) {
                    uni.showToast({
                        title: '支付失败!',
                        icon: 'error'
                    });
                    //console.log('*************支付失败');
                },

                complete: function (res) {
                    //console.log('*************支付完成');
                }
            });
        },

        //支付
        renewConfirm: function () {
            if (!this.addTime) {
                uni.showToast({
                    title: '请选择增加时间',
                    icon: 'none'
                });
                return false;
            } else {
                var that = this;
                if (app.globalData.isLogin) {
                    http.request(
                        '/member/order/renew',
                        '1',
                        'post',
                        {
                            orderId: that.OrderInfodata.orderId,
                            // "minutes": that.data.addTime * 60,
                            endTime: that.newTime,
                            payType: that.payType,
                            orderNo: that.renewOrderNo
                        },
                        app.globalData.userDatatoken.accessToken,
                        '',
                        function success(info) {
                            console.info('续费返回111===');
                            console.info(info);
                            if (info.code == 0) {
                                uni.showToast({
                                    title: '续时成功'
                                });
                                that.getrorderInfodata();
                                that.renewCancel();
                            } else {
                                uni.showModal({
                                    content: info.msg,
                                    showCancel: false
                                });
                            }
                        },
                        function fail(info) {}
                    );
                }
            }
        },

        // 取消续费重置数据
        renewCancel: function () {
            this.setData({
                renewShow: false,
                addTime: '',
                newTime: '',
                renewOrderNo: '',
                totalPay: 0,
                payType: 1
            });
        },

        //取消成功
        SucessConfirm() {
            //订单取消成功
            //刷新页面
            var that = this;
            that.getrorderInfodata();
            that.renewCancel();
        },

        // 取消弹窗
        cancelOrder(e) {
            var that = this;
            var astatus = e.currentTarget.dataset.info;
            if (astatus == 2 || astatus == 3) {
                uni.showToast({
                    title: '订单已完成，暂无法取消！',
                    icon: 'none'
                });
            } else {
                this.setData({
                    cancelOrderShow: true
                });
            }
        },

        // 提前离店
        stopOrder(e) {
            var that = this;
            var orderId = e.currentTarget.dataset.id;
            uni.showModal({
                title: '温馨提示',
                content: '提前离店不退费，会立即结束订单，已支付的押金会自动退还，请问是否确认提前离店？',
                showCancel: true,
                success(res) {
                    if (res.confirm) {
                        http.request('/member/order/closeOrder/' + orderId, '1', 'post', {}, app.globalData.userDatatoken.accessToken, '', function success(info) {
                            console.info('结束订单===');
                            if (info.code == 0) {
                                //刷新页面
                                that.getrorderInfodata();
                            } else {
                                uni.showModal({
                                    title: '温馨提示',
                                    content: info.msg,
                                    showCancel: false
                                });
                            }
                        });
                    }
                }
            });
        },

        //订单取消成功弹窗
        cancelConfirm() {
            var that = this;
            console.log('确定取消订单');
            console.log(that.OrderNo);
            if (app.globalData.isLogin) {
                if (that.OrderNo) {
                    http.request(
                        '/member/order/cancelOrder/' + that.OrderNo,
                        '1',
                        'post',
                        {
                            orderId: that.OrderInfodata.roomId
                        },
                        app.globalData.userDatatoken.accessToken,
                        '',
                        function success(info) {
                            console.info('取消订单===');
                            console.info(info);
                            if (info.code == 0) {
                                //刷新页面
                                that.getrorderInfodata();
                                that.renewCancel();
                                that.setData({
                                    cancelOrderSuccess: true
                                });
                            } else {
                                uni.showModal({
                                    content: info.msg,
                                    showCancel: false
                                });
                            }
                        },
                        function fail(info) {}
                    );
                }
            }
        },

        //获取订单详情
        getrorderInfodata: function (e) {
            var that = this;
            // console.log(that.data.OrderNo)
            http.request(
                '/member/order/getOrderInfo',
                '1',
                'get',
                {
                    orderId: that.OrderNo,
                    orderKey: that.orderKey
                },
                app.globalData.userDatatoken.accessToken,
                '获取中...',
                function success(info) {
                    console.info('订单信息===');
                    // console.info(info);
                    if (info.code === 0) {
                        that.setData({
                            OrderInfodata: info.data,
                            OrderNo: info.data.orderId,
                            orderKey: info.data.orderKey
                        });
                        console.log(that.OrderNo);
                        that.getrorderImageList();
                        that.getStoreBalance();
                    } else {
                        uni.showModal({
                            title: '温馨提示',
                            content: info.msg,
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    let pages = getCurrentPages();
                                    if (pages.length > 1) {
                                        uni.navigateBack({
                                            //返回
                                            delta: 1
                                        });
                                    }
                                    if (pages.length == 1) {
                                        uni.reLaunch({
                                            url: '/pages/index/index'
                                        });
                                    }
                                }
                            }
                        });
                    }
                },
                function fail(info) {}
            );
        },

        call: function () {
            // let that = this
            let that = this;
            var phoneLength = that.OrderInfodata.kefuPhone.length;
            if (phoneLength > 0) {
                if (phoneLength == 11) {
                    uni.makePhoneCall({
                        phoneNumber: that.OrderInfodata.kefuPhone,
                        success: function () {
                            //console.log("拨打电话成功！")
                        },
                        fail: function () {
                            //console.log("拨打电话失败！")
                        }
                    });
                } else {
                    uni.showModal({
                        title: '提示',
                        content: '客服上班时间10：00~23：00\r\n如您遇到问题，建议先查看“使用帮助”！\r\n本店客服微信号：' + that.OrderInfodata.kefuPhone,
                        confirmText: '复制',
                        complete: (res) => {
                            if (res.confirm) {
                                uni.setClipboardData({
                                    data: that.OrderInfodata.kefuPhone,
                                    success: function (res) {
                                        uni.showToast({
                                            title: '微信号已复制到剪贴板！'
                                        });
                                    }
                                });
                            } else if (res.cancel) {
                                //console.log('用户点击取消')
                            }
                        }
                    });
                }
            }
            // if(that.data.OrderInfodata.kefuPhone.length>0){
            //   //console.log("拨打电话+++")
            //   wx.makePhoneCall({
            //     phoneNumber:that.data.OrderInfodata.kefuPhone,
            //     success:function () {
            //       //console.log("拨打电话成功！")
            //     },
            //     fail:function () {
            //       //console.log("拨打电话失败！")
            //     }
            //   })
            // }
        },

        goTencentMap(e) {
            let store = this.OrderInfodata;
            this.goMap(store);
        },

        // 打开地图
        goMap(store) {
            let that = this;
            uni.openLocation({
                latitude: store.lat,
                longitude: store.lon,
                name: store.storeName,
                address: store.address,
                scale: 28
            });
        },

        //获取图片
        getrorderImageList: function (e) {
            var that = this;
            if (app.globalData.isLogin) {
                if (that.OrderInfodata.roomId) {
                    http.request(
                        '/member/order/getRoomImgs/' + that.OrderInfodata.roomId,
                        '1',
                        'get',
                        {
                            roomId: that.OrderInfodata.roomId
                        },
                        app.globalData.userDatatoken.accessToken,
                        '',
                        function success(info) {
                            console.info('图片信息===');
                            console.info(info);
                            if (info.code == 0) {
                                if (info.data) {
                                    var alist = info.data.split(',');
                                    // console.info('图片信息===1111');
                                    // console.info(alist);
                                    that.setData({
                                        RoomImageList: alist
                                    });
                                }
                            } else {
                                uni.showModal({
                                    content: info.msg,
                                    showCancel: false
                                });
                            }
                        },
                        function fail(info) {}
                    );
                }
            }
        },

        //图片点击事件
        imgYu: function (event) {
            var that = this;
            if (that.RoomImageList.length > 0) {
                var src = that.RoomImageList[0] + '?Content-Type=image/jpg'; //获取data-src
                var imgList = that.RoomImageList; //获取data-list
                //图片预览
                uni.previewImage({
                    current: src,
                    // 当前显示图片的http链接
                    urls: imgList // 需要预览的图片http链接列表
                });
            } else {
                uni.showToast({
                    title: '该房间暂无图片介绍',
                    icon: 'none'
                });
            }
        },

        //大门
        damenbindchange: function (event) {
            let that = this;
            http.request(
                '/member/order/openStoreDoor?orderKey=' + that.orderKey,
                '1',
                'post',
                {
                    orderKey: that.orderKey
                },
                app.globalData.userDatatoken.accessToken,
                '提交中...',
                function success(info) {
                    console.info('打开大门===');
                    if (info.code == 0) {
                        uni.showToast({
                            title: '操作成功',
                            icon: 'success'
                        });
                    } else {
                        uni.showModal({
                            title: '提示',
                            content: info.msg,
                            showCancel: false
                        });
                    }
                },
                function fail(info) {}
            );
        },

        openRoomDoor: function (e) {
            let that = this;
            //开房间门
            console.log('开房间门');
            http.request(
                '/member/order/openRoomDoor?orderKey=' + that.orderKey,
                '1',
                'post',
                {
                    // "orderKey":that.data.orderKey,
                },
                app.globalData.userDatatoken.accessToken,
                '提交中...',
                function success(info) {
                    console.info('房间门===');
                    console.info(info);
                    if (info.code == 0) {
                        uni.showToast({
                            title: '操作成功',
                            icon: 'success'
                        });
                        if (e == true) {
                            that.openRoomLock();
                        }
                        that.getrorderInfodata();
                    } else {
                        uni.showModal({
                            title: '提示',
                            content: info.msg,
                            showCancel: false
                        });
                    }
                },
                function fail(info) {}
            );
        },

        bindOpenRoomLock: function (event) {
            let that = this;
            let startTime = new Date(that.OrderInfodata.startTime);
            if (that.OrderInfodata.status == 0 && startTime > Date.now()) {
                uni.showModal({
                    title: '温馨提示',
                    content: '当前还未到预约时间，是否提前开始消费？',
                    success: function (res) {
                        if (res.confirm) {
                            that.openRoomDoor(true);
                            // that.openRoomLock();
                        }
                    }
                });
            } else {
                that.openRoomLock();
            }
        },

        //开密码门
        openRoomLock: function () {
            var that = this;
            if (that.OrderInfodata.lockData) {
                //本地蓝牙开锁
                lock.blueDoorOpen(that.OrderInfodata.lockData);
            } else {
                uni.showToast({
                    title: '未使用密码锁'
                });
            }
        },

        roombindchange: function (event) {
            let that = this;
            let startTime = new Date(that.OrderInfodata.startTime);
            if (that.OrderInfodata.status == 0 && startTime > Date.now()) {
                uni.showModal({
                    title: '温馨提示',
                    content: '当前还未到预约时间，是否提前开始消费？',
                    success: function (res) {
                        if (res.confirm) {
                            that.openRoomDoor();
                        }
                    }
                });
            } else {
                that.openRoomDoor();
            }
        },

        getuserinfo: function () {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/user/get',
                    '1',
                    'get',
                    {},
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('我的信息===');
                        console.info(info);
                        if (info.code == 0) {
                            that.setData({
                                userinfo: info.data
                            });
                        }
                    },
                    function fail(info) {}
                );
            } else {
                //console.log('未登录失败！')
            }
        },

        // 获取门店余额
        getStoreBalance: function () {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/user/getStoreBalance/' + that.OrderInfodata.storeId,
                    '1',
                    'get',
                    {
                        storeId: that.OrderInfodata.storeId
                    },
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('赠送余额===');
                        console.info(info);
                        if (info.code == 0) {
                            that.setData({
                                giftBalance: info.data.giftBalance,
                                balance: info.data.balance
                            });
                        }
                    },
                    function fail(info) {}
                );
            } else {
                //console.log('未登录失败！')
            }
        },

        showModel: function (msg) {
            uni.showModal({
                title: '温馨提示',
                content: msg
            });
        },

        getPrice: function (startDate) {
            var that = this;
            var day = new Date(startDate).getDay();
            switch (day) {
                case 1:
                case 2:
                case 3:
                case 4:
                    return that.OrderInfodata.workPrice;
                case 0:
                case 5:
                case 6:
                    return that.OrderInfodata.roomPrice;
            }
        }
    }
};
</script>
<style>
@import './orderDetail.css';
</style>
